<?php
class CompleXml_Db_Doctrine
{
    static public function init ($connection, $models_path = null)
    {
        require_once 'Doctrine.php';
        spl_autoload_register(array('Doctrine' , 'autoload'));
        Doctrine_Manager::connection($connection);
        if (! is_null($models_path)) {
            Doctrine::loadModels($models_path);
        }
    }
    
    static public function getPagerArray(Doctrine_Pager $pager)
    {
        $result = array();
        if (!$pager->getExecuted()){
            require_once 'CompleXml/Db/Exception.php';
            throw new CompleXml_Db_Exception('Pager not executed');
        }
        $result['have-pager'] = (int) $pager->haveToPaginate();
        $result['first-page'] = $pager->getFirstPage();
        $result['first-indice'] = $pager->getFirstIndice();
        $result['last-page'] = $pager->getLastPage();
        $result['last-indice'] = $pager->getLastIndice();
        $result['result-count'] = $pager->getNumResults();
        $result['next-page'] = $pager->getNextPage();
        $result['previous-page'] = $pager->getPreviousPage();
        $result['current-page'] = $pager->getPage();
        $result['results-on-page'] = $pager->getResultsInPage();
        return $result;
    }
}